package com.bstek.uflo.form.action.impl;

import org.hibernate.Session;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import com.bstek.dorado.view.View;
import com.bstek.dorado.web.DoradoContext;
import com.bstek.uflo.console.component.ParameterType;
import com.bstek.uflo.console.component.UfloProcessDiagram;
import com.bstek.uflo.form.action.Action;
import com.bstek.uflo.form.action.FormData;

/**
 * @author Jacky.gao
 * @since 2013年11月12日
 */
@Component("uflo.form.seeProcessImageAction")
public class SeeProcessImageAction implements Action {

	public String getName() {
		return "查看流程图";
	}
	
	public String getIcon() {
		return "url(skin>common/icons.gif) -300px -20px";
	}

	public void onViewInit(View view) {
		UfloProcessDiagram diagram=new UfloProcessDiagram();
		diagram.setRequestParameterType(ParameterType.taskId);
		diagram.setRequestParameterValue(DoradoContext.getCurrent().getRequest().getParameter("taskId"));
		diagram.setId("ufloProcessDiagram");
		view.addChild(diagram);
	}

	public void execute(FormData formData,Session session) {
	}

	public String getClickScript(String actionId) {
		StringBuffer sb=new StringBuffer();
		String taskId=DoradoContext.getCurrent().getRequest().getParameter("taskId");
		if(StringUtils.isEmpty(taskId)){
			sb.append("dorado.MessageBox.alert(\"当前没有taskId参数，无法进行此操作.\")");
			return sb.toString();
		}
		sb.append("var diagram=view.id(\"ufloProcessDiagram\");");
		sb.append("diagram.show()");
		return sb.toString();
	}
}
